:Init

@setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
@pushd %~dp0
@prompt $_
@echo off

if "%1" == "" goto Usage
goto Detach

:Usage
@echo.
@echo Unmounts a virtual hard drive (VHD) file.  
@echo.
@echo DETACHVHD [drive:][path]filename
@echo.
@echo   [drive:][path][filename]
@echo               Specifies the full path the VHD file to detach.
@echo.
@goto End

:CheckPaths
if not exists "%1" (
    @echo Unable to locate virtual hard drive (VHD) file at '%2'.
    @goto End
)

:Detach
echo select vdisk file="%1" > "%TEMP%\accelcon.detachvhd.script.txt"
echo detach vdisk >> "%TEMP%\accelcon.detachvhd.script.txt"
@diskpart.exe -s "%TEMP%\accelcon.detachvhd.script.txt"
@ping 1.0.0.0 -n 5 -w 1000 >NUL

REM ~~( END )~~
@echo.
@echo Completed.
@echo.
:End